<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./art-template(1).js"></script>
</head>

<body>
    <div class="box"></div>
    <script id="con" type="text/html">
      <div>
    <ul>
        {{each data as item}}
        <li>
            <a href="">{{item.title}}</a>
            {{if item.list.length > 0}}
            <!-- 引入另一个模板
            语法:include 模板的id 传入这个模板的对象 -->
                {{include "con2" item}}
            {{/if}}
        </li>
        {{/each}}
    </ul>
       </div>
    </script>
    <script id="con2" type="text/html">
        <ol>
            {{each list as item}}
            <li>{{item}}</li>
            {{/each}}
        </ol>
    </script>
    <script>
        var res = {
            data: [{
                title: "标题1",
                list: ["liebiao1", "liebiao2", "liebiao3"]
            }, {

                title: "标题2",
                list: []

            }]
        }

        var str = template("con", res);
        console.log(str);
        document.querySelector(".box").innerHTML = str;
    </script>
</body>

</html>